<template>
  <div>
    <van-field label='名称' v-model='form.name'/>
    选择课程<select v-model='form.course_id'>
    <option :value="i.id" v-for='i in courselist'>{{ i.title }}</option>
  </select>
    上传视频
    <van-uploader :after-read="vedio_upload"/>


    <van-button @click='add'>添加</van-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {'video_url': ''},
      courselist: []
    }
  },
  methods: {
    vedio_upload(file) {
      if (this.form.course_id) {
        //视频上传
        let formdata = new FormData()
        formdata.append('file', file.file)
        formdata.append('course_id', this.form.course_id)
        this.axios.post('vedioUpload', formdata).then(res => {
          this.form.video_url = res.data.url
        })
      } else {
        alert('请选择课程后再上传视频')
      }

    },
    add() {
      this.axios.post('jieM').then(res => {
        
      })
    },
    //获取课程列表
    getcourselist() {
      this.axios.get('courseM').then(res => {
        this.courselist = res.data.list
      })
    }
  },
  mounted() {
    this.getcourselist()
  },
}
</script>
<style lang="">

</style>
